<!--  -->
<template>
    <div>
<div class="m-container">
    <div class="ui container m-pad-tb-big m-opacity ">
        <div class="ui segment" >
            <div id="blog-form" class="ui form">

                <div class="required two fields m-margin-tb-large">
                    <div class="field">
                        <div class="ui labeled input">
                            <div class="ui label basic teal">用户昵称</div>
                            <input type="text" v-model="user.nickname">
                        </div>
                    </div>
                    <div class="field">
                        <div class="ui labeled input">
                            <div class="ui label basic teal">用户邮箱</div>
                            <input type="text" v-model="user.email">
                        </div>
                    </div>
                </div>
                <div class="required two fields m-margin-tb-large">
                    <div class="field">
                        <div class="ui labeled input">
                            <div class="ui label basic teal">登录账号</div>
                            <input type="text" v-model="user.username">
                        </div>
                    </div>
                    <div class="field">
                        <div class="ui labeled input">
                            <div class="ui label basic teal">登陆密码</div>
                            <input type="text" v-model="user.password">
                        </div>
                    </div>
                </div>
                <div class="field m-margin-tb-large">
                    <div class="ui labeled input">
                        <div class="ui label basic teal">头像图片</div>
                        <input type="text" v-model="user.avatar">
                    </div>
                </div>
                <div class="required field" style="height:750px; overflow:scroll;">
                    <mavon-editor style="height: 100%;width: 100%;" v-model="user.content"></mavon-editor>
                </div>
                <div class="ui negative message" v-show="error">
                    <i class="close icon" @click="closeMsg"></i>
                    <div class="header">提示:</div>
                    <p>{{message}}</p>
                </div>
                <div class="ui container right aligned">
                    <button type="button" class="ui button" onclick="window.history.go(-1)">返回</button>
                    <button type="button" id="save-btn" class="ui blue button" @click="submit()">保存</button>
                </div>
            </div>
        </div>
    </div>
</div>
<br>
<br>
<br>

    </div>
</template>

<script>
import { mavonEditor } from 'mavon-editor'
import 'mavon-editor/dist/css/index.css'
export default {
    data () {
        return {
            error:false,
            message:"",
            user:{
                content:""
            }
        };
    },
    methods:{
        submit(){
            var _this = this
            _this.axios.post("/admin/saveAdmin",{
                id:_this.user.id,
                nickname:_this.user.nickname,
                username:_this.user.username,
                password:_this.user.password,
                avatar:_this.user.avatar,
                email:_this.user.email,
                content:_this.user.content
            }).then(res=>{
                if(res.data.status === 200){
                    _this.$store.commit('setToken',res.data.token)
                    _this.$store.commit('setUser',res.data.user)
                    _this.$router.push({path:'/admin/blogs'})
                }else{
                    _this.message=res.data.msg
                    _this.error=true
                }
            }).catch(e=>{
                console.log(e)
            })
        },
        closeMsg(){
            this.error = false
        }
    },
    created(){
        var _this = this
        _this.axios.get("/admin/getAdminInfo")
        .then(res=>{
            _this.user = res.data.user
        }).catch(e=>{
            console.log(e)
        })
    },
    components:{
        mavonEditor
    },
}

</script>
<style scoped>
</style>